<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/common.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<div class='form-group'>
				<label class='col-md-2 control-label'>流程编码</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='流程编码' type='text' name='flowCode' id='flowCode' data-bv-notempty='true' data-bv-notempty-message='流程编码 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>流程属性</label>
				<div class='col-md-10'>
					<select name="flowAttribute" id="flowAttribute" data-bv-notempty='true' data-bv-notempty-message='流程属性 不能为空'>
						<option val="0">普通流程</option>
						<option val="1">复合流程</option>
					</select>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>流程归属业务</label>
				<div class='col-md-10'>
					<select name="flowType" id="flowType" data-bv-notempty='true' data-bv-notempty-message='流程归属业务 不能为空'>
					</select>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>流程名称</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='流程名称' type='text' name='flowName' id='flowName' data-bv-notempty='true' data-bv-notempty-message='流程名称 不能为空'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>归属机构</label>
				<div class='col-md-10'>
					<input class='form-control' type='text' name='followOrgId' id='followOrgId' onclick="openIframeOrgList(this)" readonly="readonly" placeholder='点击选择'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-2 control-label'>流程描述</label>
				<div class='col-md-10'>
					<input class='form-control' placeholder='流程描述' type='text' name='flowRemarks' id='flowRemarks' data-bv-notempty='true' data-bv-notempty-message='流程描述 不能为空'>
				</div>
			</div>
			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
					    <button class="btn btn-primary" onclick="location.href='flowList.html'">返回</button>
						<button class="btn btn-primary" type="submit" onclick="add()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>
	<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script type="text/javascript">
		layui.use(['layer','laydate'], function(){
		    var layer = layui.layer;
		});
		getFlowTaskType();
		function add() {
			$('#form').bootstrapValidator();
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();
		    formdata.followOrgId = $("#followOrgId").attr("followOrgId");
			$.ajax({
				type : 'post',
				url : urlRootPrefix + '/orgs',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					if(!data.success){
						layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
						$("button[type='submit']").removeAttr("disabled");
						return;
					}
					layer.msg("添加成功", {shift: -1, time: 1000}, function(){
                        location.href = "flowList.html";
                    });
				}
			});
		}
		function getFlowTaskType(){
		   	$.ajax({
		       type : 'get',
		       url : urlRootPrefix + '/flowTaskTypes/listVo',
		       success : function(data) {
		          if(!data.success){
		           	layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
					return;
				  }
		          var data = data.data;
		          var typeHtml = "";
		          for(var i=0;i<data.length;i++){
		           typeHtml += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
		          }
		          $("#flowType").append(typeHtml);
		        }
		    });
		}
		function openIframeOrgList(f) {
			var dt = {'ids':$(f).attr("followOrgId"),'names':$(f).val()};
			layer.open({
				type : 2,
				title : "选择归属业务员",
				shadeClose : false,
				shade : 0.8,
				maxmin : false, //开启最大化最小化按钮
				area : [ '800px', '650px' ],
				content : urlRootPrefix + "/pages/common/orgList.html",
				success: function ( layero,index) {
		        	//找到它的子窗口的body
		            var body = layer.getChildFrame('body', index), iframeWin = window[layero.find('iframe')[0]['name']];  
		          //为子窗口元素赋值
		            body.contents().find("#ids").val(dt.ids);
		            body.contents().find("#names").val(dt.names);
		            //调用子窗口的事件
		            iframeWin.initData();
		            iframeWin.init();
		        },
				btn : [ '确定', '取消' ],
				yes : function(index, layero) {
					//按钮【按钮一】的回调
					var body = layer.getChildFrame('body', index);
					$("#followOrgId").attr("followOrgId",body.contents().find("#ids").val());
					$("#followOrgId").val(body.contents().find("#names").val());
					layer.close(index);
				}
			});
		}
	</script>
</body>
</html>
